package com.chenhao.springcloud.chenhaodesignservice.pattern.creational.singleton;

/**
 * Description:懒汉式双重检测
 *
 * @author chenhao
 * @date 2020/12/17 11:23
 */
public class LazyDoubleCheckSingleton {
    // volatile保证内存可见性
    private  volatile  static  LazyDoubleCheckSingleton lazyDoubleCheckSingleton =null;
    private LazyDoubleCheckSingleton(){

    }

    public  static LazyDoubleCheckSingleton getLazySingleton() {
        if (lazyDoubleCheckSingleton==null){
            synchronized (LazyDoubleCheckSingleton.class){
                if (lazyDoubleCheckSingleton==null){
                    lazyDoubleCheckSingleton = new LazyDoubleCheckSingleton();
                }
            }

        }
        return lazyDoubleCheckSingleton;
    }
}
